package com.zspringboot.demo.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import com.zspringboot.demo.common.Result;
import com.zspringboot.demo.entity.User;
import com.zspringboot.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @program: springboot2
 * @description:
 * @author: LaoLang
 * @create: 2024-02-24 21:18
 * @version:1.0
 **/
@RestController
@RequestMapping("/echarts")
public class EchartsController {
    @Autowired
    private IUserService iUserService;
    @GetMapping("/zspringboot")
    public Result get(){
        Map<String, Object> map = new HashMap<>();
        map.put("x", CollUtil.newArrayList("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"));
        map.put("y", CollUtil.newArrayList(150, 230, 224, 218, 135, 147, 260));
        return Result.success(map);
    }

    @GetMapping("/members")
    public Result members(){
        List<User> list = iUserService.list();
        AtomicInteger q1 = new AtomicInteger();// 第一季度
        AtomicInteger q2 = new AtomicInteger();// 第二季度
        AtomicInteger q3 = new AtomicInteger();// 第三季度
        AtomicInteger q4 = new AtomicInteger();// 第四季度
        list.forEach((e)->{
            Date creteTime = e.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(creteTime);
            switch (quarter){
                case Q1: q1.addAndGet(1);break;
                case Q2: q2.addAndGet(1);break;
                case Q3: q3.addAndGet(1);break;
                case Q4: q4.addAndGet(1);break;
                default:break;
            }

        });
        return Result.success(CollUtil.newArrayList(q1,q2,q3,q4));
    }
}
